package cn.controller;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.kpi.service.usualassessment.IUserUATMzpdService;
import com.mangofactory.swagger.models.dto.ApiListing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.common.ExceResult;
import cn.common.LayTable;
import cn.common.PageString;
import cn.filter.LoginCheck;
import cn.kpi.entity.sys.OrgEntity;
import cn.kpi.entity.sys.UserEntity;
import cn.kpi.entity.usualassessment.UsAssTempCreateIndexEntity;
import cn.kpi.entity.usualassessment.UserTemplateEntity;
import cn.kpi.entity.usualassessment.UserUATPjSummaryEntity;
import cn.kpi.entity.usualassessment.UserUATZpAtt;
import cn.kpi.entity.usualassessment.UserUATZpDetailEntity;
import cn.kpi.entity.usualassessment.UserUATZpSummaryEntity;
import cn.kpi.entity.vtiondpline.VtDpUserListEntity;
import cn.kpi.service.sys.IUserService;
import cn.kpi.service.usualassessment.IUsAssTemplateService;
import cn.kpi.service.usualassessment.IUserUATZpService;
import cn.kpi.service.usualassessment.IUserUsAssTempService;
import cn.kpi.service.vtiondpline.IVtDpUserService;

@Controller
@RequestMapping("userusasstempzp")
public class UserUsAssTempZpController extends BaseController {
	@Autowired
	private IUserUATMzpdService iUserUATMzpdService;
	
	@Autowired
	private IUserUsAssTempService iUserUsAssTempService;
	
	@Autowired
	private IUsAssTemplateService iUsAssTemplateService;
	
	@Autowired
	private IUserUATZpService iUserUATZpService;
	
	@Autowired
	private IUserService iUserService;
	
	@Autowired 
	private IVtDpUserService iVtDpUserService;
	
	@RequestMapping(value = "/user_usasstemp_zp_list")
	public String UserUsassTempZpList(Model model) {
		try{
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH )+1;
			int quarter=1;
			switch(month){
			case 1:
			case 2:
			case 3:
				quarter=1;
				break;
			case 4:
			case 5:
			case 6:
				quarter=2;
				break;
			case 7:
			case 8:
			case 9:
				quarter=3;
				break;
			case 10:
			case 11:
			case 12:
				quarter=4;
				break;
			}
			if(quarter==1){
				year=year-1;
				quarter=4;
			}
			else{
				quarter=quarter-1;
			}
			model.addAttribute("year", year);
			model.addAttribute("quarter", quarter);
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_list";
	}
	
	@RequestMapping(value = "/user_usasstemp_zp_bm_list")
	public String UserUsassTempZpBmList(Model model) {
		try{
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH )+1;
			int quarter=1;
			switch(month){
			case 1:
			case 2:
			case 3:
				quarter=1;
				break;
			case 4:
			case 5:
			case 6:
				quarter=2;
				break;
			case 7:
			case 8:
			case 9:
				quarter=3;
				break;
			case 10:
			case 11:
			case 12:
				quarter=4;
				break;
			}
			if(quarter==1){
				year=year-1;
				quarter=4;
			}
			else{
				quarter=quarter-1;
			}
			model.addAttribute("year", year);
			model.addAttribute("quarter", quarter);
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_bm_list";
	}
	
	@RequestMapping(value = "/user_usasstemp_zp_show")
	public String UserUsassTempZpShow(Model model,int year,int quarter) {
		try{
			UserEntity userentity=iUserService.GetUserById(this.GetLoginUserId());
			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById((this.GetLoginUserId()));
			UserUATZpSummaryEntity sumentity=iUserUATZpService.GetUserUATZpSummary(this.GetLoginUserId(), entityusertemp.getTemplateid(), year, quarter);


			 if(sumentity==null)
			 {
			 	sumentity=new UserUATZpSummaryEntity();
				 sumentity.setYear(0);
				 sumentity.setQuarter(0);
			 }
			List<UserUATZpDetailEntity> lst=iUserUATZpService.GetUserUATZpDetailList(sumentity.getUsasszpid(), this.GetLoginUserId());
			model.addAttribute("lst", lst);
			 model.addAttribute("sumentity", sumentity);
			model.addAttribute("userentity", userentity);
			
			UserUATZpAtt entityatt=new UserUATZpAtt();
			entityatt=iUserUATZpService.GetUserUATZpAtt(sumentity.getUsasszpid());
			model.addAttribute("entityatt", entityatt);
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_show";
	}
	
	@RequestMapping(value = "/user_usasstemp_zp_bm_show")
	public String UserUsassTempZpBmShow(Model model,Long userid,int year,int quarter,Long templateid) {
		try{
			UserEntity userentity=iUserService.GetUserById(userid);
			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById(userid);
			UserUATZpSummaryEntity sumentity=iUserUATZpService.GetUserUATZpSummary(userid, templateid, year, quarter);
			List<UserUATZpDetailEntity> lst=iUserUATZpService.GetUserUATZpDetailList(sumentity.getUsasszpid(), userid);
			model.addAttribute("lst", lst);
			model.addAttribute("sumentity", sumentity);
			model.addAttribute("userentity", userentity);
			
			UserUATZpAtt entityatt=new UserUATZpAtt();
			entityatt=iUserUATZpService.GetUserUATZpAtt(sumentity.getUsasszpid());
			model.addAttribute("entityatt", entityatt);
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		return "usualassessment/user_usasstemp_zp_bm_show";
	}
	
	@RequestMapping(value = "/user_usasstemp_zp_edit")
	public String UserUsassTempZpEdit(Model model,Long usasszpid) {
		try{
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH )+1;
			int quarter=1;
			switch(month){
				case 1:
				case 2:
				case 3:
					quarter=1;
					break;
				case 4:
				case 5:
				case 6:
					quarter=2;
					break;
				case 7:
				case 8:
				case 9:
					quarter=3;
					break;
				case 10:
				case 11:
				case 12:
					quarter=4;
					break;
			}
			if(quarter!=1){
				quarter=quarter-1;
			}
			model.addAttribute("quarter",quarter);

			UserUATZpSummaryEntity sumentity=new UserUATZpSummaryEntity();
			UserUATZpAtt entityatt=new UserUATZpAtt();
			
			UserEntity userentity=iUserService.GetUserById(this.GetLoginUserId());
			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById((this.GetLoginUserId()));
			if(usasszpid>0){
				List<UserUATZpDetailEntity> lst=iUserUATZpService.GetZpDetailListRowSpan(usasszpid);
				model.addAttribute("lst", lst);
				String createids = "";
				for (int i = 0; i < lst.size(); i++) {
					UserUATZpDetailEntity entity = lst.get(i);
					createids+=entity.getCreateid()+",";
				}
				model.addAttribute("createids", createids.substring(0, createids.length() - 1));
				model.addAttribute("entityusertemp", entityusertemp);
				sumentity=iUserUATZpService.GetUserUATZpSummaryById(usasszpid);
				
			 entityatt=iUserUATZpService.GetUserUATZpAtt(usasszpid);
			}
			else{
				List<UsAssTempCreateIndexEntity> lst=iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
				model.addAttribute("lst", lst);
				String createids = "";
				for (int i = 0; i < lst.size(); i++) {
					UsAssTempCreateIndexEntity entity = lst.get(i);
					createids+=entity.getCreateid()+",";
				}
				model.addAttribute("createids", createids.substring(0, createids.length() - 1));
				model.addAttribute("entityusertemp", entityusertemp);
			}
			
			model.addAttribute("userentity", userentity);
			model.addAttribute("sumentity", sumentity);
			model.addAttribute("usasszpid", usasszpid);
			model.addAttribute("entityatt", entityatt);
			
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_edit";
	}
	
	@RequestMapping(value = "/user_usasstemp_zp_bm_edit_new")
	public String UserUsassTempZpBmEditNew(Model model,Long usasszpid,Long userid,int year,int quarter) {
		try{
			UserUATZpSummaryEntity sumentity=new UserUATZpSummaryEntity();
			
			UserUATZpAtt entityatt=new UserUATZpAtt();
			
			UserEntity userentity=iUserService.GetUserById(userid);
			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById(userid);
			if(usasszpid>0){
				List<UserUATZpDetailEntity> lst=iUserUATZpService.GetZpDetailListRowSpan(usasszpid);
				model.addAttribute("lst", lst);
				String createids = "";
				for (int i = 0; i < lst.size(); i++) {
					UserUATZpDetailEntity entity = lst.get(i);
					createids+=entity.getCreateid()+",";
				}
					model.addAttribute("createids", createids.substring(0, createids.length() - 1));
				model.addAttribute("entityusertemp", entityusertemp);
				sumentity=iUserUATZpService.GetUserUATZpSummaryById(usasszpid);
				
				entityatt=iUserUATZpService.GetUserUATZpAtt(usasszpid);
			}
			else{
				List<UsAssTempCreateIndexEntity> lst=iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
				model.addAttribute("lst", lst);
				String createids = "";
				for (int i = 0; i < lst.size(); i++) {
					UsAssTempCreateIndexEntity entity = lst.get(i);
					createids+=entity.getCreateid()+",";
				}
				model.addAttribute("createids", createids.substring(0, createids.length() - 1));
				model.addAttribute("entityusertemp", entityusertemp);
			}
			
			model.addAttribute("userentity", userentity);
			model.addAttribute("sumentity", sumentity);
			model.addAttribute("usasszpid", usasszpid);
			model.addAttribute("userid", userid);
			model.addAttribute("year", year);
			model.addAttribute("quarter", quarter);
			model.addAttribute("entityatt", entityatt);
			
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_bm_edit_new";
	}
	
	
	
	
	
	@RequestMapping(value = "/user_usasstemp_zp_bm_edit")
	public String UserUsassTempZpBmEdit(Model model,Long usasszpid) {
		try{
			
			model.addAttribute("usasszpid", usasszpid);
			
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_bm_edit";
	}
	
	
	@RequestMapping(value = "/user_usasstemp_zp_bm_edit_show")
	public String UserUsassTempZpBmEditShow(Model model,Long usasszpid,Long userid,int year,int quarter) {
		try{
			UserUATZpSummaryEntity sumentity=new UserUATZpSummaryEntity();
			
			UserEntity userentity=iUserService.GetUserById(userid);
			UserTemplateEntity entityusertemp=iUserUsAssTempService.GetUserUsAssTempById(userid);
			if(usasszpid>0){
				List<UserUATZpDetailEntity> lst=iUserUATZpService.GetZpDetailListRowSpan(usasszpid);
				model.addAttribute("lst", lst);
				String createids = "";
				for (int i = 0; i < lst.size(); i++) {
					UserUATZpDetailEntity entity = lst.get(i);
					createids+=entity.getCreateid()+",";
				}
				model.addAttribute("createids", createids.substring(0, createids.length() - 1));
				model.addAttribute("entityusertemp", entityusertemp);
				sumentity=iUserUATZpService.GetUserUATZpSummaryById(usasszpid);
			}
			else{
				List<UsAssTempCreateIndexEntity> lst=iUsAssTemplateService.GetTemplateCreateIndexListRowSpan(entityusertemp.getTemplateid());
				model.addAttribute("lst", lst);
				String createids = "";
				for (int i = 0; i < lst.size(); i++) {
					UsAssTempCreateIndexEntity entity = lst.get(i);
					createids+=entity.getCreateid()+",";
				}
				model.addAttribute("createids", createids.substring(0, createids.length() - 1));
				model.addAttribute("entityusertemp", entityusertemp);
			}
			
			model.addAttribute("userentity", userentity);
			model.addAttribute("sumentity", sumentity);
			model.addAttribute("usasszpid", usasszpid);
			model.addAttribute("userid", userid);
			model.addAttribute("year", year);
			model.addAttribute("quarter", quarter);
			
		}
		catch(Exception ex){
			
		}
		return "usualassessment/user_usasstemp_zp_bm_edit_show";
	}

	//固化0808
	@ResponseBody
	@RequestMapping(value = "/add_userusasstempzp")
	public String AddUserUsAssTempZp(HttpServletRequest request, HttpServletResponse response) {
		
		try {
			String createids = request.getParameter("createids");
			if(createids==null||createids.length()<=0){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
			}
			String strtemplateid=request.getParameter("templateid");
			if(strtemplateid==null||strtemplateid.length()<=0){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
			}
			String struserid=request.getParameter("userid");
			if(struserid==null||struserid.length()<=0){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
			}
			
			Long usasszpid=Long.parseLong(request.getParameter("usasszpid"));

			
			
			Long templateid=Long.parseLong(strtemplateid);
			Long userid=Long.parseLong(struserid);
			UserEntity user = this.GetUserById(userid);//拿到保存用户详细信息

			String strnf=request.getParameter("nf");
			String strquarter=request.getParameter("quarter");
			String stzpjg=request.getParameter("zpjg");
			String stgzyj=request.getParameter("gzyj");
			String stzczwt=request.getParameter("czwt");
			
			String[] createidArr=createids.split(",");
			//Map<Long, Integer> map = new HashMap<Long, Integer>(); 
			Map<Long, Float> map = new HashMap<Long, Float>(); 
			//int totalscore=0;
			Float totalscore=0f;
			for(int i=0;i<createidArr.length;i++){
				String strzpscore=request.getParameter("zpscore_"+createidArr[i]);
				//Integer zpscore=Integer.parseInt(strzpscore);
				//map.put(Long.parseLong(createidArr[i]), zpscore);
				Float zpscore=Float.parseFloat(strzpscore);
				map.put(Long.parseLong(createidArr[i]), zpscore);
				totalscore+=zpscore;
			}
			
			
			Float cqts=Float.parseFloat(request.getParameter("cqts"));
			Float nxjts=Float.parseFloat(request.getParameter("nxjts"));
			Float tqjts=Float.parseFloat(request.getParameter("tqjts"));
			Float hjts=Float.parseFloat(request.getParameter("hjts"));
			Float sangjts=Float.parseFloat(request.getParameter("sangjts"));
			Float bjts=Float.parseFloat(request.getParameter("bjts"));
			Float syjts=Float.parseFloat(request.getParameter("syjts"));
			Float sjts=Float.parseFloat(request.getParameter("sjts"));
			Float gsts=Float.parseFloat(request.getParameter("gsts"));
			Float qtts=Float.parseFloat(request.getParameter("qtts"));
			Integer cdcc=Integer.parseInt(request.getParameter("cdcc"));
			Integer ztcc=Integer.parseInt(request.getParameter("ztcc"));
			Integer kgcs=Integer.parseInt(request.getParameter("kgcs"));
			Float jbts=Float.parseFloat(request.getParameter("jbts"));
			
			UserUATZpSummaryEntity entity=new UserUATZpSummaryEntity();
			entity.setCzwt(stzczwt);
			entity.setGzyj(stgzyj);
			entity.setQuarter(Integer.parseInt(strquarter));
			entity.setStatus(0);
			entity.setTemplateid(templateid);
			entity.setTotalscore(totalscore);
			entity.setUserid(userid);
			entity.setZpjg(stzpjg);
			entity.setYear(Integer.parseInt(strnf));
			//固化开始
			entity.setSzdw(user.getSzdw());
			entity.setOrgname(user.getOrgname());
			entity.setUserstatus(user.getUserstatus());
			entity.setRsgxszdw(user.getRsgxszdw());
			entity.setRsgxorgname(user.getRsgxorgname());
			//固化结束
			
			
			UserUATZpAtt zpatt=new UserUATZpAtt();
			zpatt.setBjts(bjts);
			zpatt.setCdcc(cdcc);
			zpatt.setCqts(cqts);
			zpatt.setGsts(gsts);
			zpatt.setHjts(hjts);
			zpatt.setKgcs(kgcs);
			zpatt.setNxjts(nxjts);
			zpatt.setQtts(qtts);
			zpatt.setQuarter(Integer.parseInt(strquarter));
			zpatt.setSangjts(sangjts);
			zpatt.setSjts(sjts);
			zpatt.setStatus(0);
			zpatt.setSyjts(syjts);
			zpatt.setTqjts(tqjts);
			zpatt.setUsasszpid(usasszpid);
			zpatt.setUserid(userid);
			zpatt.setYear(Integer.parseInt(strnf));
			zpatt.setZtcc(ztcc);
			zpatt.setJbts(jbts);
			//固化开始
			zpatt.setSzdw(user.getSzdw());
			zpatt.setSzdwname(user.getOrgname());
			zpatt.setUserstatus(user.getUserstatus());
			zpatt.setRsgxszdw(user.getRsgxszdw());
			zpatt.setRsgxszdwname(user.getRsgxorgname());

			int iResult=0;
			if(usasszpid>0){
				entity.setUsasszpid(usasszpid);
				 //iResult=iUserUATZpService.UpdateUserUATZp(entity, userid, templateid, map);
				iResult=iUserUATZpService.UpdateUserUATZpAtt(entity, userid, templateid, map,zpatt);
			}
			else{
			  UserUATZpSummaryEntity sumentity=iUserUATZpService.GetUserUATZpSummary(this.GetLoginUserId(), templateid, entity.getYear(), entity.getQuarter());
			  if(sumentity!=null){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'本季度已提交过数据，请勿重复提交')</script>");
			  }
			  String vtdpwhere="";
			  int year=entity.getYear();
				switch(entity.getQuarter()){
				case 0:
					//vtdpwhere+=" AND begintime>='"+year+"-01-01 00:00:00' AND begintime<='"+year+"-12-31 23:59:59'";
					//vtdpwhere+=" AND begintime>='"+year+"-01-01 00:00:00' AND begintime<='"+year+"-03-31 23:59:59'";
					break;
				case 1:
					//vtdpwhere+=" AND begintime>='"+year+"-01-01 00:00:00' AND begintime<='"+year+"-03-31 23:59:59'";
					vtdpwhere+="AND (( begintime<='"+year+"-01-01 00:00:00' AND endtime>='"+year+"-01-01 00:00:00') OR ( begintime<='"+year+"-03-31 23:59:59' AND endtime>='"+year+"-03-31 23:59:59')) ";
					break;
				case 2:
					//vtdpwhere+=" AND begintime>='"+year+"-04-01 00:00:00' AND begintime<='"+year+"-06-30 23:59:59'";
					vtdpwhere+=" AND (( begintime<='"+year+"-04-01 00:00:00' AND endtime>='"+year+"-04-01 00:00:00') OR ( begintime<='"+year+"-06-30 23:59:59' AND endtime>='"+year+"-06-30 23:59:59')) ";
					break;
				case 3:
					//vtdpwhere+=" AND begintime>='"+year+"-07-01 00:00:00' AND begintime<='"+year+"-09-30 23:59:59'";
					vtdpwhere+="AND (( begintime<='"+year+"-07-01 00:00:00' AND endtime>='"+year+"-07-01 00:00:00') OR ( begintime<='"+year+"-09-30 23:59:59' AND endtime>='"+year+"-09-30 23:59:59')) ";
					break;
				case 4:
					//vtdpwhere+=" AND begintime>='"+year+"-10-01 00:00:00' AND begintime<='"+year+"-12-31 23:59:59'";
					vtdpwhere+="AND (( begintime<='"+year+"-10-01 00:00:00' AND endtime>='"+year+"-10-01 00:00:00') OR ( begintime<='"+year+"-12-31 23:59:59' AND endtime>='"+year+"-12-31 23:59:59')) ";
					break;
				}
				
			  
			  List<VtDpUserListEntity> lst=iVtDpUserService.GetVtDpListByUseridAndWhere(userid,vtdpwhere);
				for (int i = 0; i < lst.size(); i++) {
					VtDpUserListEntity item = lst.get(i);
					String zzpdcllx = item.getZzpdcllx();
					String mzpdcllx = item.getMzpdcllx();
					if (zzpdcllx.equals("不参加考核")) {
						return renderStringScript(response, "<script>window.parent.CloseDialog(0,'特殊事项限定不参加考核')</script>");
					}
					if (mzpdcllx.equals("不参加考核")) {
						return renderStringScript(response, "<script>window.parent.CloseDialog(0,'特殊事项限定不参加考核')</script>");
					}
				}
			  
			  
			  //iResult=iUserUATZpService.InsertUserUATZp(entity, userid, templateid, map);
				iResult=iUserUATZpService.InsertUserUATZpAtt(entity, userid, templateid, map,zpatt);
			}
			
			return renderStringScript(response, "<script>window.parent.CloseDialog(" + iResult + ")</script>");
		}
		catch (Exception ex) {
			ex.printStackTrace();
			return renderStringScript(response, "<script>window.parent.CloseDialog(0)</script>");
		}
	}
	
	
	@ResponseBody
	@RequestMapping(value = "/add_userusasstempzpbm")
	public String AddUserUsAssTempZpBm(HttpServletRequest request, HttpServletResponse response) {
		
		try {
			String createids = request.getParameter("createids");
			if(createids==null||createids.length()<=0){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
			}
			String strtemplateid=request.getParameter("templateid");
			if(strtemplateid==null||strtemplateid.length()<=0){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
			}
			String struserid=request.getParameter("userid");
			if(struserid==null||struserid.length()<=0){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'参数有误')</script>");
			}
			
			Long usasszpid=Long.parseLong(request.getParameter("usasszpid"));

	
			Long templateid=Long.parseLong(strtemplateid);
			Long userid=Long.parseLong(struserid);
			UserEntity user = this.GetUserById(userid);//拿到保存用户详细信息
			String strnf=request.getParameter("nf");
			String strquarter=request.getParameter("quarter");
			String stzpjg=request.getParameter("zpjg");
			String stgzyj=request.getParameter("gzyj");
			String stzczwt=request.getParameter("czwt");
			
			Float cqts=Float.parseFloat(request.getParameter("cqts"));
			Float nxjts=Float.parseFloat(request.getParameter("nxjts"));
			Float tqjts=Float.parseFloat(request.getParameter("tqjts"));
			Float hjts=Float.parseFloat(request.getParameter("hjts"));
			Float sangjts=Float.parseFloat(request.getParameter("sangjts"));
			Float bjts=Float.parseFloat(request.getParameter("bjts"));
			Float syjts=Float.parseFloat(request.getParameter("syjts"));
			Float sjts=Float.parseFloat(request.getParameter("sjts"));
			Float gsts=Float.parseFloat(request.getParameter("gsts"));
			Float qtts=Float.parseFloat(request.getParameter("qtts"));
			Integer cdcc=Integer.parseInt(request.getParameter("cdcc"));
			Integer ztcc=Integer.parseInt(request.getParameter("ztcc"));
			Integer kgcs=Integer.parseInt(request.getParameter("kgcs"));
			Float jbts=Float.parseFloat(request.getParameter("jbts"));



			String[] createidArr=createids.split(",");
//			Map<Long, Integer> map = new HashMap<Long, Integer>(); 
//			int totalscore=0;
			Map<Long, Float> map = new HashMap<Long, Float>(); 
			Float totalscore=0f;
			for(int i=0;i<createidArr.length;i++){
				String strzpscore=request.getParameter("zpscore_"+createidArr[i]);
				//Integer zpscore=Integer.parseInt(strzpscore);
				Float zpscore=Float.parseFloat(strzpscore);
				map.put(Long.parseLong(createidArr[i]), zpscore);
				totalscore+=zpscore;
			}
			
			
			UserUATZpAtt zpatt=new UserUATZpAtt();
			zpatt.setBjts(bjts);
			zpatt.setCdcc(cdcc);
			zpatt.setCqts(cqts);
			zpatt.setGsts(gsts);
			zpatt.setHjts(hjts);
			zpatt.setKgcs(kgcs);
			zpatt.setNxjts(nxjts);
			zpatt.setQtts(qtts);
			zpatt.setQuarter(Integer.parseInt(strquarter));
			zpatt.setSangjts(sangjts);
			zpatt.setSjts(sjts);
			zpatt.setStatus(0);
			zpatt.setSyjts(syjts);
			zpatt.setTqjts(tqjts);
			zpatt.setUsasszpid(usasszpid);
			zpatt.setUserid(userid);
			zpatt.setYear(Integer.parseInt(strnf));
			zpatt.setZtcc(ztcc);
			zpatt.setJbts(jbts);
			//固化开始
			zpatt.setSzdw(user.getSzdw());
			zpatt.setSzdwname(user.getOrgname());
			zpatt.setUserstatus(user.getUserstatus());
			zpatt.setRsgxszdw(user.getRsgxszdw());
			zpatt.setRsgxszdwname(user.getRsgxorgname());
			//固化结束
			
			UserUATZpSummaryEntity entity=new UserUATZpSummaryEntity();
			entity.setCzwt(stzczwt);
			entity.setGzyj(stgzyj);
			entity.setQuarter(Integer.parseInt(strquarter));
			entity.setStatus(0);
			entity.setTemplateid(templateid);
			entity.setTotalscore(totalscore);
			entity.setUserid(userid);
			entity.setZpjg(stzpjg);
			entity.setYear(Integer.parseInt(strnf));
			//固化开始
			entity.setSzdw(user.getSzdw());
			entity.setRsgxorgname(user.getOrgname());
			entity.setUserstatus(user.getUserstatus());
			entity.setRsgxszdw(user.getRsgxszdw());
			entity.setRsgxorgname(user.getRsgxorgname());
			//固化结束
		
			int iResult=0;
			if(usasszpid>0){
				entity.setUsasszpid(usasszpid);
				 //iResult=iUserUATZpService.UpdateUserUATZp(entity, userid, templateid, map);
				iResult=iUserUATZpService.UpdateUserUATZpAtt(entity, userid, templateid, map,zpatt);
			}
			else{
			  UserUATZpSummaryEntity sumentity=iUserUATZpService.GetUserUATZpSummary(userid, templateid, entity.getYear(), entity.getQuarter());
			  if(sumentity!=null){
				return renderStringScript(response, "<script>window.parent.CloseDialog(0,'本季度已提交过数据，请勿重复提交')</script>");
			  }
			  
			  String vtdpwhere="";
			  int year=entity.getYear();
			  switch(entity.getQuarter()){
				case 0:
					//vtdpwhere+=" AND begintime>='"+year+"-01-01 00:00:00' AND begintime<='"+year+"-12-31 23:59:59'";
					//vtdpwhere+=" AND begintime>='"+year+"-01-01 00:00:00' AND begintime<='"+year+"-03-31 23:59:59'";
					break;
				case 1:
					//vtdpwhere+=" AND begintime>='"+year+"-01-01 00:00:00' AND begintime<='"+year+"-03-31 23:59:59'";
					vtdpwhere+="AND (( begintime<='"+year+"-01-01 00:00:00' AND endtime>='"+year+"-01-01 00:00:00') OR ( begintime<='"+year+"-03-31 23:59:59' AND endtime>='"+year+"-03-31 23:59:59')) ";
					break;
				case 2:
					//vtdpwhere+=" AND begintime>='"+year+"-04-01 00:00:00' AND begintime<='"+year+"-06-30 23:59:59'";
					vtdpwhere+=" AND (( begintime<='"+year+"-04-01 00:00:00' AND endtime>='"+year+"-04-01 00:00:00') OR ( begintime<='"+year+"-06-30 23:59:59' AND endtime>='"+year+"-06-30 23:59:59')) ";
					break;
				case 3:
					//vtdpwhere+=" AND begintime>='"+year+"-07-01 00:00:00' AND begintime<='"+year+"-09-30 23:59:59'";
					vtdpwhere+="AND (( begintime<='"+year+"-07-01 00:00:00' AND endtime>='"+year+"-07-01 00:00:00') OR ( begintime<='"+year+"-09-30 23:59:59' AND endtime>='"+year+"-09-30 23:59:59')) ";
					break;
				case 4:
					//vtdpwhere+=" AND begintime>='"+year+"-10-01 00:00:00' AND begintime<='"+year+"-12-31 23:59:59'";
					vtdpwhere+="AND (( begintime<='"+year+"-10-01 00:00:00' AND endtime>='"+year+"-10-01 00:00:00') OR ( begintime<='"+year+"-12-31 23:59:59' AND endtime>='"+year+"-12-31 23:59:59')) ";
					break;
				}
				
				

			  List<VtDpUserListEntity> lst=iVtDpUserService.GetVtDpListByUseridAndWhere(userid,vtdpwhere);
			  //System.out.println(JSON.toJSONString(lst));
				for (int i = 0; i < lst.size(); i++) {
					VtDpUserListEntity item = lst.get(i);
					String zzpdcllx = item.getZzpdcllx();
					String mzpdcllx = item.getMzpdcllx();
					if (zzpdcllx!=null&&zzpdcllx.equals("不参加考核")) {
						return renderStringScript(response, "<script>window.parent.CloseDialog(0,'特殊事项限定不参加考核')</script>");
					}
					if (mzpdcllx!=null&&mzpdcllx.equals("不参加考核")) {
						return renderStringScript(response, "<script>window.parent.CloseDialog(0,'特殊事项限定不参加考核')</script>");
					}
				}
				System.out.println(2);
			  //iResult=iUserUATZpService.InsertUserUATZp(entity, userid, templateid, map);
				iResult=iUserUATZpService.InsertUserUATZpAtt(entity, userid, templateid, map,zpatt);
			}
			
			return renderStringScript(response, "<script>window.parent.CloseDialog(" + iResult + ")</script>");
		}
		catch (Exception ex) {
			ex.printStackTrace();
			return renderStringScript(response, "<script>window.parent.CloseDialog(0)</script>");
		}
	}
	
	
	@LoginCheck(description = true)
	@ResponseBody
	@RequestMapping(value = "/get_list")
	public LayTable<UserUATZpSummaryEntity> GetList(HttpServletRequest request) {

		List<UserUATZpSummaryEntity> lst=null;
		LayTable<UserUATZpSummaryEntity> layTable=new LayTable<UserUATZpSummaryEntity>();
		try {
			String year = request.getParameter("year");
			String quarter = request.getParameter("quarter");
			String where="";
			if(year!=null&&year.length()>0){
				where+=" AND year="+year;
			}
            if(quarter!=null&&quarter.length()>0){
            	where+=" AND quarter="+quarter;
			}
            int page=Integer.parseInt(request.getParameter("page"));
			int limit=Integer.parseInt(request.getParameter("limit"));
			int beginrow=(page-1)*limit;
			int endrow=limit;

			//11.1日，只有在职才参加平时考核
			where += " AND userstatus='在职'";
			String limitwhere=where+" ORDER BY year DESC,quarter DESC LIMIT "+beginrow+","+endrow;
			
			//lst = iUserUATZpService.GetUserUATZpSummaryList(this.GetLoginUserId(),limitwhere);
			lst = iUserUATZpService.GetUserUATZpSummaryListTssx(this.GetLoginUserId(),limitwhere,Integer.parseInt(year),Integer.parseInt(quarter));
			for (int i = 0; i < lst.size(); i++) {
				int numr=(page-1)*limit+(i + 1);
				lst.get(i).setRowNum(numr);
			}

			layTable.setCode(0);
			layTable.setCount(iUserUATZpService.GetUserUATZpSummaryListCount(this.GetLoginUserId(),where));
			layTable.setData(lst);
			
		} catch (Exception e) {
			layTable.setCode(500);
		}
		return layTable;
	}
	
	@LoginCheck(description = true)
	@ResponseBody
	@RequestMapping(value = "/get_list_bm")
	public LayTable<UserUATZpSummaryEntity> GetListBm(HttpServletRequest request) {

		List<UserUATZpSummaryEntity> lst=null;
		LayTable<UserUATZpSummaryEntity> layTable=new LayTable<UserUATZpSummaryEntity>();
		try {
			String year = request.getParameter("year");
			String quarter = request.getParameter("quarter");
			String where="";
			if(year!=null&&year.length()>0){
				where+=" AND year="+year;
			}
            if(quarter!=null&&quarter.length()>0){
            	where+=" AND quarter="+quarter;
			}
            int page=Integer.parseInt(request.getParameter("page"));
			int limit=Integer.parseInt(request.getParameter("limit"));
			int beginrow=(page-1)*limit;
			int endrow=limit;
			
			String orgids=this.GetOrgListByRole();
			if(this.GetLoginUserId()>0){
				where+=" AND userid IN (SELECT userid FROM t_sys_user WHERE szdw IN ("+orgids+")) ";
			}
			
			
			String limitwhere=where+" ORDER BY year DESC,quarter DESC LIMIT "+beginrow+","+endrow;
			
			//lst = iUserUATZpService.GetUserUATZpSummaryListByWhere(limitwhere);
			lst = iUserUATZpService.GetUserUATZpSummaryListByWhereTssx(limitwhere,Integer.parseInt(year),Integer.parseInt(quarter));
			for (int i = 0; i < lst.size(); i++) {
				int numr=(page-1)*limit+(i + 1);
				lst.get(i).setRowNum(numr);
			}

			layTable.setCode(0);
			layTable.setCount(iUserUATZpService.GetUserUATZpSummaryListCountByWhere(where));
			layTable.setData(lst);
			
		} catch (Exception e) {
			layTable.setCode(500);
		}
		return layTable;
	}

	
	@ResponseBody
	@RequestMapping(value = "/delete_useruatzp")
	public ExceResult DeleteUserUATZp(HttpServletRequest request,HttpServletResponse response){
		ExceResult result=new ExceResult();
		result.setCode(400);
		result.setResult(0);
		try{
		 Long usasszpid=Long.parseLong(request.getParameter("usasszpid"));
		 Long userid=this.GetLoginUserId();
		// int iResult=iUserUATZpService.DeleteUATZp(usasszpid, userid);
		 int iResult=iUserUATZpService.DeleteUATZpAtt(usasszpid, userid);
		 if(iResult>0){
				result.setCode(200);
				result.setResult(iResult);
				result.setMsg("操作成功");
			}
			else{
				result.setCode(300);
				result.setResult(iResult);
				result.setMsg("操作失败");
			}
		}
		catch(Exception ex){
			result.setCode(500);
			result.setResult(0);
			result.setMsg("操作异常");
		}
		return result;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "/delete_useruatzp_bm")
	public ExceResult DeleteUserUATZpBm(HttpServletRequest request,HttpServletResponse response){
		ExceResult result=new ExceResult();
		result.setCode(400);
		result.setResult(0);
		try{
		 Long usasszpid=Long.parseLong(request.getParameter("usasszpid"));
		 Long userid=Long.parseLong(request.getParameter("userid"));
		 //int iResult=iUserUATZpService.DeleteUATZp(usasszpid, userid);
		 int iResult=iUserUATZpService.DeleteUATZpAtt(usasszpid, userid);
		 if(iResult>0){
				result.setCode(200);
				result.setResult(iResult);
				result.setMsg("操作成功");
			}
			else{
				result.setCode(300);
				result.setResult(iResult);
				result.setMsg("操作失败");
			}
		}
		catch(Exception ex){
			result.setCode(500);
			result.setResult(0);
			result.setMsg("操作异常");
		}
		return result;
	}


	
	@ResponseBody
	@RequestMapping(value = "/update_status")
	public ExceResult UpdateStatus(HttpServletRequest request,HttpServletResponse response){
		ExceResult result=new ExceResult();
		result.setCode(400);
		result.setResult(0);
		try{
		 Long usasszpid=Long.parseLong(request.getParameter("usasszpid"));
		 int status=Integer.parseInt(request.getParameter("status"));
		 int year=Integer.parseInt(request.getParameter("year"));
		 int quarter=Integer.parseInt(request.getParameter("quarter"));
		 
		 Long userid=this.GetLoginUserId();
		 //int iResult=iUserUATZpService.UpdateStatus(usasszpid, userid,year,quarter,status);
		 int iResult=iUserUATZpService.UpdateStatusAtt(usasszpid, userid,year,quarter,status);
		 if(iResult>0){
				result.setCode(200);
				result.setResult(iResult);
				result.setMsg("操作成功");
			}
			else{
				result.setCode(300);
				result.setResult(iResult);
				result.setMsg("操作失败");
			}
		}
		catch(Exception ex){
			result.setCode(500);
			result.setResult(0);
			result.setMsg("操作异常");
		}
		return result;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "/update_status_bm")
	public ExceResult UpdateStatusBm(HttpServletRequest request,HttpServletResponse response){
		ExceResult result=new ExceResult();
		result.setCode(400);
		result.setResult(0);
		try{
		 Long usasszpid=Long.parseLong(request.getParameter("usasszpid"));
		 int status=Integer.parseInt(request.getParameter("status"));
		 int year=Integer.parseInt(request.getParameter("year"));
		 int quarter=Integer.parseInt(request.getParameter("quarter"));
		 
		 Long userid=Long.parseLong(request.getParameter("userid"));
		 //int iResult=iUserUATZpService.UpdateStatus(usasszpid, userid,year,quarter,status);
		 int iResult=iUserUATZpService.UpdateStatusAtt(usasszpid, userid,year,quarter,status);
		 if(iResult>0){
				result.setCode(200);
				result.setResult(iResult);
				result.setMsg("操作成功");
			}
			else{
				result.setCode(300);
				result.setResult(iResult);
				result.setMsg("操作失败");
			}
		}
		catch(Exception ex){
			result.setCode(500);
			result.setResult(0);
			result.setMsg("操作异常");
		}
		return result;
	}
	
			
	@LoginCheck(description = true)
	@ResponseBody
	@RequestMapping(value = "/get_zplist_bm")
	public LayTable<UserUATZpSummaryEntity> GetZpListBm(HttpServletRequest request) {

		List<UserUATZpSummaryEntity> lst=null;
		LayTable<UserUATZpSummaryEntity> layTable=new LayTable<UserUATZpSummaryEntity>();
		try {
			String realname=request.getParameter("realname");
			int year = Integer.parseInt(request.getParameter("year"));
			int quarter = Integer.parseInt(request.getParameter("quarter"));
			String where="";

			
			int page=Integer.parseInt(request.getParameter("page"));
			int limit=Integer.parseInt(request.getParameter("limit"));
			int beginrow=(page-1)*limit;
			int endrow=limit;
			
			where+=this.GetUserListByRole();

			String status ="";
			int count = 0;
			String orgwhere = "";
			if (this.GetOrgListByRole() != "") {
				orgwhere = " AND orgid IN (" + this.GetOrgListByRole() + ")";
			}
			List<Map> list = iUserUATMzpdService.GetPjOrgSumList(orgwhere, year, quarter);

			//1月27修改，所有的部门填报了，才是status=2
			status = "2";
			String notCountBM = "19,44,45,46,47,48";
			for (Map map : list) {
				if(notCountBM.contains(map.get("orgid").toString())) continue;
				if(map.get("status") == null){
					status = "";
					break;//跳出
				}else {
					 if(map.get("status").toString().equals("1")){
					 	status = "1";
					 	break;//跳出
					}
				}
			}



			//11.1日，只有在职才参加平时考核
			where += " AND userstatus='在职'";

			if(status.equals("2")) {
				if(realname!=null&&realname.length()>0){
					where+=" AND userid in (select userid from t_sys_user where realname LIKE '%"+realname+"%')";
				}
				lst = iUserUATZpService.GetOldUserZpListProcess(where, year, quarter, beginrow, endrow);
				where += " AND year = "+year+" AND quarter = "+quarter;
				count = iUserUATZpService.GetOldUserZpListProcessCount(where);
			}else{
				if(realname!=null&&realname.length()>0){
					where+=" AND realname LIKE '%"+realname+"%'";
				}
				lst = iUserUATZpService.GetUserZpListProcess(where, year, quarter, beginrow, endrow);
				count = iUserUATZpService.GetUserZpListProcessCount(where);
			}
			for (int i = 0; i < lst.size(); i++) {
				int numr=(page-1)*limit+(i + 1);
				lst.get(i).setRowNum(numr);
			}

			layTable.setCode(0);
			layTable.setCount(count);
			layTable.setData(lst);
			
		} catch (Exception e) {
			layTable.setCode(500);
			e.printStackTrace();
		}
		return layTable;
	}
}
